//
//  TabBarViewController.swift
//  06-UINavigationBar、UIToolbar和UITabBar
//
//  Created by VEER on 2022/3/8.
//

import UIKit



class TabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
//        var imgView = UIImageView(image: UIImage(systemName: "house"))
//        view.addSubview(imgView)
//        imgView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)

        // Do any additional setup after loading the view.
        let vc = UINavigationController(rootViewController: ViewController1())
        let tabItem = UITabBarItem(title: "首页", image: UIImage.house, selectedImage: UIImage.house_fill)
        vc.tabBarItem = tabItem
        self.addChild(vc)
        
        let vc1 = UINavigationController(rootViewController: ViewController2())
        let tabItem1 = UITabBarItem(title: "我的", image: UIImage.person, selectedImage: UIImage.person_fill)
        vc1.tabBarItem = tabItem1
        self.addChild(vc1)
        
        setupTab()
    }
    
    
    func setupTab() {
        
        if #available(iOS 13.0, *) {
            // UITabBar
            let tabBarAppearance = UITabBarAppearance()
            // 背景色
            tabBarAppearance.backgroundColor = .white
            // 设置UITabBarItem
            let itemAppearance = UITabBarItemAppearance()
            // 未选中的图标颜色
            itemAppearance.normal.iconColor = .black
            // 未选中的文字颜色
            itemAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.lightGray]
            // 角标背景色
            itemAppearance.normal.badgeBackgroundColor = .black
            // 角标颜色
            itemAppearance.normal.badgeTextAttributes = [.foregroundColor: UIColor.white]
            // 选中的图标颜色
            itemAppearance.selected.iconColor = .blue
            // 选中的文字颜色
            itemAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.blue]
            // 选中的角标背景色
            itemAppearance.selected.badgeBackgroundColor = .white
            // 选中的角标颜色
            itemAppearance.selected.badgeTextAttributes = [.foregroundColor: UIColor.black]
            // 生效
            tabBarAppearance.stackedLayoutAppearance = itemAppearance
            self.tabBar.scrollEdgeAppearance = tabBarAppearance
            self.tabBar.standardAppearance = tabBarAppearance
        } else {

            self.tabBar.barTintColor = .white
            self.tabBar.tintColor = .black
            self.tabBar.unselectedItemTintColor = .white
            tabBarItem.badgeColor = .black
            tabBarItem.setBadgeTextAttributes([.foregroundColor: UIColor.white], for: .normal)
        }
    }

}

